Conditions | 1 |
Paths | 1 |
Total Lines | 74 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
43 | describe('Movie', function () { |
||
44 | beforeEach(function (done) { |
||
45 | serve.start(done) |
||
46 | }) |
||
47 | |||
48 | afterEach(function (done) { |
||
49 | serve.stop(done) |
||
50 | }) |
||
51 | |||
52 | before(function () { |
||
53 | movie.setEndpoint({list: 'http://localhost:3000/response'}) |
||
54 | }) |
||
55 | |||
56 | it ('expect to be an error if endpoint is not an object', function () { |
||
57 | expect(() => { |
||
58 | movie.setEndpoint('string') |
||
59 | }).to.throw('endpoint must be an object') |
||
60 | }) |
||
61 | |||
62 | it ('expect to be an error if param is not an object', function () { |
||
63 | expect(() => { |
||
64 | movie.setParams('string') |
||
65 | }).to.throw('params must be an object') |
||
66 | }) |
||
67 | |||
68 | it ('expect return an array', function () { |
||
69 | req() |
||
70 | |||
71 | return movie.get() |
||
72 | .then(response => { |
||
73 | expect(response.data.movies).to.be.an('array') |
||
74 | }) |
||
75 | }) |
||
76 | |||
77 | it ('expect return an array and contains genres with action property', function () { |
||
78 | req() |
||
79 | |||
80 | return movie.findByGenre('action') |
||
81 | .then(function (response) { |
||
82 | expect(response.data.movies[0]) |
||
83 | .to.be.an('object') |
||
84 | .to.have.deep.property('genres[0]', 'Action') |
||
85 | }) |
||
86 | }) |
||
87 | |||
88 | it ('expect return an array and contains quality with 3D property', function () { |
||
89 | req() |
||
90 | |||
91 | return movie.findByQuality('3D') |
||
92 | .then(function (response) { |
||
93 | expect(response.data.movies[0]) |
||
94 | .to.be.an('object') |
||
95 | .to.have.deep.property('torrents[0].quality', '3D') |
||
96 | }) |
||
97 | }) |
||
98 | |||
99 | it ('expect return an array and contain rating higher than argument', function () { |
||
100 | req() |
||
101 | |||
102 | return movie.findByRating('8') |
||
103 | .then(function (response) { |
||
104 | expect(response.data.movies[0].rating).to.be.above(8) |
||
105 | }) |
||
106 | }) |
||
107 | |||
108 | it ('expect return to be an array and have title match with Star Wars', function () { |
||
109 | req() |
||
110 | |||
111 | return movie.search('Star Wars') |
||
112 | .then(response => { |
||
113 | expect(response.data.movies[0].title).to.match(/Star Wars/g) |
||
114 | }) |
||
115 | }) |
||
116 | }) |
||
117 |